package com.szrt.java.day20170112.ch06;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class InputStreamReaderTest {
	
	
	
	/**
	 * 家庭作业： 直接把异常抛出。 try catch finally
	 * 
	 * InputStreamReader 直接抄一遍
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		
		
		File file = new File("src/com/szrt/java/day20170112/ch06/szrt.txt");
		
		InputStream in = new FileInputStream(file);
		
		InputStreamReader isr = new InputStreamReader(in);
		
		
		char[] b  = new char[3];
		
		int len;
		
		int counter =0;
		while((len=isr.read(b))!=-1){
			counter++;
			String str = new String(b,0,len);
			System.out.print(str);
		}
		
		isr.close();
		in.close();
		System.out.println();
		System.out.println(counter);
	}
	
	
	public static void xx() throws IOException{
		InputStreamReader isr = new InputStreamReader(new FileInputStream(new File("src/com/szrt/java/day20170112/ch06/szrt.txt")));
		char[] b  = new char[3];
		int len;
		int counter =0;
		while((len=isr.read(b))!=-1){
			counter++;
			String str = new String(b,0,len);
			System.out.print(str);
		}
		
		isr.close();
		System.out.println();
		System.out.println(counter);
	}

}
